// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   BarChart.java

package org.achartengine.chart;

import android.graphics.*;
import android.graphics.drawable.GradientDrawable;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.renderer.SimpleSeriesRenderer;
import org.achartengine.renderer.XYMultipleSeriesRenderer;

// Referenced classes of package org.achartengine.chart:
//			XYChart

public class BarChart extends XYChart
{
	public static final class Type extends Enum
	{

		public static final Type DEFAULT;
		public static final Type STACKED;
		private static final Type $VALUES[];

		public static Type[] values()
		{
			return (Type[])$VALUES.clone();
		}

		public static Type valueOf(String s)
		{
			return (Type)Enum.valueOf(org/achartengine/chart/BarChart$Type, s);
		}

		static 
		{
			DEFAULT = new Type("DEFAULT", 0);
			STACKED = new Type("STACKED", 1);
			$VALUES = (new Type[] {
				DEFAULT, STACKED
			});
		}

		private Type(String s, int i)
		{
			super(s, i);
		}
	}


	public static final String TYPE = "Bar";
	private static final int SHAPE_WIDTH = 12;
	protected Type mType;

	BarChart()
	{
		mType = Type.DEFAULT;
	}

	public BarChart(XYMultipleSeriesDataset xymultipleseriesdataset, XYMultipleSeriesRenderer xymultipleseriesrenderer, Type type)
	{
		super(xymultipleseriesdataset, xymultipleseriesrenderer);
		mType = Type.DEFAULT;
		mType = type;
	}

	protected RectF[] clickableAreasForPoints(float af[], float f, int i)
	{
		int j = mDataset.getSeriesCount();
		int k = af.length;
		RectF arectf[] = new RectF[k / 2];
		float f1 = getHalfDiffX(af, k, j);
		for (int l = 0; l < k; l += 2)
		{
			float f2 = af[l];
			float f3 = af[l + 1];
			if (mType == Type.STACKED)
			{
				arectf[l / 2] = new RectF(f2 - f1, f3, f2 + f1, f);
			} else
			{
				float f4 = (f2 - (float)j * f1) + (float)(i * 2) * f1;
				arectf[l / 2] = new RectF(f4, f3, f4 + 2.0F * f1, f);
			}
		}

		return arectf;
	}

	public void drawSeries(Canvas canvas, Paint paint, float af[], SimpleSeriesRenderer simpleseriesrenderer, float f, int i)
	{
		int j = mDataset.getSeriesCount();
		int k = af.length;
		paint.setColor(simpleseriesrenderer.getColor());
		paint.setStyle(android.graphics.Paint.Style.FILL);
		float f1 = getHalfDiffX(af, k, j);
		for (int l = 0; l < k; l += 2)
		{
			float f2 = af[l];
			float f3 = af[l + 1];
			drawBar(canvas, f2, f, f2, f3, f1, j, i, paint);
		}

		paint.setColor(simpleseriesrenderer.getColor());
	}

	protected void drawBar(Canvas canvas, float f, float f1, float f2, float f3, float f4, int i, 
			int j, Paint paint)
	{
		int k = mDataset.getSeriesAt(j).getScaleNumber();
		if (mType == Type.STACKED)
		{
			drawBar(canvas, f - f4, f3, f2 + f4, f1, k, j, paint);
		} else
		{
			float f5 = (f - (float)i * f4) + (float)(j * 2) * f4;
			drawBar(canvas, f5, f3, f5 + 2.0F * f4, f1, k, j, paint);
		}
	}

	private void drawBar(Canvas canvas, float f, float f1, float f2, float f3, int i, int j, 
			Paint paint)
	{
		SimpleSeriesRenderer simpleseriesrenderer = mRenderer.getSeriesRendererAt(j);
		if (simpleseriesrenderer.isGradientEnabled())
		{
			float f4 = (float)toScreenPoint(new double[] {
				0.0D, simpleseriesrenderer.getGradientStopValue()
			}, i)[1];
			float f5 = (float)toScreenPoint(new double[] {
				0.0D, simpleseriesrenderer.getGradientStartValue()
			}, i)[1];
			float f6 = Math.max(f4, f1);
			float f7 = Math.min(f5, f3);
			int k = simpleseriesrenderer.getGradientStopColor();
			int l = simpleseriesrenderer.getGradientStartColor();
			int i1 = l;
			int j1 = k;
			if (f1 < f4)
			{
				paint.setColor(k);
				canvas.drawRect(Math.round(f), Math.round(f1), Math.round(f2), Math.round(f6), paint);
			} else
			{
				j1 = getGradientPartialColor(k, l, (f5 - f6) / (f5 - f4));
			}
			if (f3 > f5)
			{
				paint.setColor(l);
				canvas.drawRect(Math.round(f), Math.round(f7), Math.round(f2), Math.round(f3), paint);
			} else
			{
				i1 = getGradientPartialColor(l, k, (f7 - f4) / (f5 - f4));
			}
			GradientDrawable gradientdrawable = new GradientDrawable(android.graphics.drawable.GradientDrawable.Orientation.BOTTOM_TOP, new int[] {
				i1, j1
			});
			gradientdrawable.setBounds(Math.round(f), Math.round(f6), Math.round(f2), Math.round(f7));
			gradientdrawable.draw(canvas);
		} else
		{
			canvas.drawRect(Math.round(f), Math.round(f1), Math.round(f2), Math.round(f3), paint);
		}
	}

	private int getGradientPartialColor(int i, int j, float f)
	{
		int k = Math.round(f * (float)Color.alpha(i) + (1.0F - f) * (float)Color.alpha(j));
		int l = Math.round(f * (float)Color.red(i) + (1.0F - f) * (float)Color.red(j));
		int i1 = Math.round(f * (float)Color.green(i) + (1.0F - f) * (float)Color.green(j));
		int j1 = Math.round(f * (float)Color.blue(i) + (1.0F - f) * (float)Color.blue(j));
		return Color.argb(k, l, i1, j1);
	}

	protected void drawChartValuesText(Canvas canvas, XYSeries xyseries, SimpleSeriesRenderer simpleseriesrenderer, Paint paint, float af[], int i)
	{
		int j = mDataset.getSeriesCount();
		float f = getHalfDiffX(af, af.length, j);
		for (int k = 0; k < af.length; k += 2)
		{
			int l = k / 2;
			if (xyseries.getY(l) == 1.7976931348623157E+308D)
				continue;
			float f1 = af[k];
			if (mType == Type.DEFAULT)
				f1 += (float)(i * 2) * f - ((float)j - 1.5F) * f;
			drawText(canvas, getLabel(xyseries.getY(l)), f1, af[k + 1] - simpleseriesrenderer.getChartValuesSpacing(), paint, 0.0F);
		}

	}

	public int getLegendShapeWidth(int i)
	{
		return 12;
	}

	public void drawLegendShape(Canvas canvas, SimpleSeriesRenderer simpleseriesrenderer, float f, float f1, int i, Paint paint)
	{
		float f2 = 6F;
		canvas.drawRect(f, f1 - f2, f + 12F, f1 + f2, paint);
	}

	protected float getHalfDiffX(float af[], int i, int j)
	{
		int k = i;
		if (i > 2)
			k = i - 2;
		float f = (af[i - 2] - af[0]) / (float)k;
		if (f == 0.0F)
			f = 10F;
		if (mType != Type.STACKED)
			f /= j;
		return (float)((double)f / ((double)getCoeficient() * (1.0D + mRenderer.getBarSpacing())));
	}

	protected float getCoeficient()
	{
		return 1.0F;
	}

	protected boolean isRenderNullValues()
	{
		return true;
	}

	public double getDefaultMinimum()
	{
		return 0.0D;
	}

	public String getChartType()
	{
		return "Bar";
	}
}
